#!/usr/bin/php
<?php
// This script checks the impressions logged against the certain trait values (Sites and Areas) for a given visitor
// This script checks only the current day -or- if a YYYY-MM-DD string is added to the commandline it checks that day.

error_reporting(E_ERROR | E_PARSE);

// setup command line args (commandline only)
if (isset($argv[1])) { $datestamp = $argv[1]; }
else {  $datestamp = date("Y-m-d"); }
$testtime = strtotime ($datestamp);
// echo $testtime."\n";
$day_of_the_week = date('l', $testtime);
$full_date = date('l, F j, Y', $testtime);
echo "\n  Query for: ".$full_date."\n";

$expected = array (
    "Monday"    => array("1" => "3", "2" => "0", "3" => "3", "4" => "0", "5" => "3", "6" => "1", "7" => "0"),
    "Tuesday"   => array("1" => "3", "2" => "0", "3" => "3", "4" => "1", "5" => "3", "6" => "1", "7" => "0"),
    "Wednesday" => array("1" => "0", "2" => "1", "3" => "0", "4" => "0", "5" => "3", "6" => "1", "7" => "0"),
    "Thursday"  => array("1" => "0", "2" => "0", "3" => "0", "4" => "3", "5" => "3", "6" => "1", "7" => "0"),
    "Friday"    => array("1" => "1", "2" => "3", "3" => "1", "4" => "3", "5" => "3", "6" => "1", "7" => "0"),
    "Saturday"  => array("1" => "0", "2" => "3", "3" => "0", "4" => "3", "5" => "3", "6" => "1", "7" => "0"),
    "Sunday"    => array("1" => "3", "2" => "3", "3" => "3", "4" => "0", "5" => "3", "6" => "1", "7" => "1")
);
// Username, password and schema for the database connection.
$username="aimatch";
$password="RMSAdmin";
$database="canary";

// Connect to the database and run the query
mysql_connect('w19',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

// Retrieve Current Numbers from the database
$query1 = "select served from bigsum where date=\"".$datestamp."\" and site=3 and area=11 ";
$query2 = "select served from bigsum where date=\"".$datestamp."\" and site=4 and area=12 ";
$query3 = "select served from bigsum where date=\"".$datestamp."\" and site=5 and area=13 ";
$query4 = "select served from bigsum where date=\"".$datestamp."\" and site=6 and area=14 ";
$query5 = "select served from bigsum where date=\"".$datestamp."\" and site=7 and area=15 ";
$query6 = "select served from bigsum where date=\"".$datestamp."\" and site=8 and area=16 ";
$query7 = "select served from bigsum where date=\"".$datestamp."\" and site=9 and area=17 ";

$v1_result=mysql_query($query1);
$v1_impressions=mysql_result($v1_result,0); 
if(!$v1_impressions) { $v1_impressions = 0; }
$v2_result=mysql_query($query2);
$v2_impressions=mysql_result($v2_result,0); 
if(!$v2_impressions) { $v2_impressions = 0; }
$v3_result=mysql_query($query3);
$v3_impressions=mysql_result($v3_result,0); 
if(!$v3_impressions) { $v3_impressions = 0; }
$v4_result=mysql_query($query4);
$v4_impressions=mysql_result($v4_result,0); 
if(!$v4_impressions) { $v4_impressions = 0; }
$v5_result=mysql_query($query5);
$v5_impressions=mysql_result($v5_result,0); 
if(!$v5_impressions) { $v5_impressions = 0; }
$v6_result=mysql_query($query6);
$v6_impressions=mysql_result($v6_result,0); 
if(!$v6_impressions) { $v6_impressions = 0; }
$v7_result=mysql_query($query7);
$v7_impressions=mysql_result($v7_result,0); 
if(!$v7_impressions) { $v7_impressions = 0; }
echo "\n  Visitor: Actual Impressions | Expected Impressions \n";
echo "     Visitor 1 Impressions: ".$v1_impressions." | ".$expected[$day_of_the_week][1]."\n";
echo "     Visitor 2 Impressions: ".$v2_impressions." | ".$expected[$day_of_the_week][2]."\n";
echo "     Visitor 3 Impressions: ".$v3_impressions." | ".$expected[$day_of_the_week][3]."\n";
echo "     Visitor 4 Impressions: ".$v4_impressions." | ".$expected[$day_of_the_week][4]."\n";
echo "     Visitor 5 Impressions: ".$v5_impressions." | ".$expected[$day_of_the_week][5]."\n";
echo "     Visitor 6 Impressions: ".$v6_impressions." | ".$expected[$day_of_the_week][6]."\n";
echo "     Visitor 7 Impressions: ".$v7_impressions." | ".$expected[$day_of_the_week][7]."\n";
?>

